function doLogin(){
	$('#spLoginInfo').html('');
	var username	= $('#txtUsername').val();
	var password	= $('#txtPassword').val();
	var verify		= $('#txtVerify').val();
	var loginUrl	= $('#hdLoginUrl').val();
	
	$('#spLoginInfo').html('正在登录...');
	
	$.ajax({
	    url: loginUrl,
	    type: 'POST',
	    data:{'username':username,'password':password,'verify':verify,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code<=0){
				$('#spLoginInfo').html('登录失败，请检查你的输入！');
			}else{
				document.location	= res.data.forward;
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function getReport(){
	var startDate		= $('#txtStart').val();
	var endDate			= $('#txtEnd').val();
	var getReportUrl	= $('#hdGetReportUrl').val();
	
	if(!isDate(startDate)){
		startDate	= '';
	}
	
	if(!isDate(endDate)){
		endDate		= '';
	}
	
	if(startDate=='' || endDate==''){
		alert('请选择要获取报表的开始/结束日期');
		return;
	}
	$('#btnGet').attr('disabled',true);
	$('#spLoading').css('display','block');
	
	$.ajax({
	    url: getReportUrl,
	    type: 'POST',
	    data:{'startDate':startDate,'endDate':endDate,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
	    	$('#btnGet').attr('disabled',false);
	    	$('#spLoading').css('display','none');
			if(res.code==200){
				alert('报表数据获取成功，请到交易报表页查看！');
				document.location	= res.data.forward;
			}else if(res.code==400){
				alert('结束日期必须在从开始日期开始30天之内！');
			}else{
				alert('报表数据获取出错，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function getYestodayReport(yestoday){
	var getReportUrl	= $('#hdGetReportUrl').val();
	
	$.ajax({
	    url: getReportUrl,
	    type: 'POST',
	    data:{'startDate':yestoday,'endDate':yestoday,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				alert('昨日淘宝客交易数据更新成功！');
				document.location.reload();
			}else{
				alert('更新出错，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function isDate(val)
{
  var reg = /^\d{4}-\d{1,2}-\d{1,2}$/;
  return reg.test(val);
}

function hideCategory(cid,hide){
	if(hide==0){
		if(!confirm('取消屏蔽后该类目和所有子类的内容都可见，确定要取消屏蔽么？')){
			return;
		}
	}else{
		if(!confirm('屏蔽类目后该类目和所有子类的内容都不可见，确定要屏蔽该类目么？')){
			return;
		}
	}
	var hideUrl	= $('#hdHideUrl').val();
	
	$.ajax({
	    url: hideUrl,
	    type: 'POST',
	    data:{'cid':cid,'hide':hide,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				document.location.reload();
			}else{
				alert('操作失败，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function updateModuleData(id){
	var updateUrl	= $('#hdUpdateUrl').val();
	
	$.ajax({
	    url: updateUrl,
	    type: 'POST',
	    data:{'id':id,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				alert('更新成功！');
			}else{
				alert('操作失败，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function clearTemplateCache(){
	var url	= $('#hdUrl').val();
	$('#clearLink').attr('href','javascript:void(0)');
	$.ajax({
	    url: url,
	    type: 'GET',
	    data:{'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				alert('缓存清除成功！');
			}else{
				alert('操作失败，请重新尝试！');
			}
			$('#clearLink').attr('href','javascript:clearTemplateCache()');
		},
		error:function(res){
			alert(res.responseText);
			$('#clearLink').attr('href','javascript:clearTemplateCache()');
		}
	});
}

function checkReturn(id,status){
	var hideUrl	= $('#hdHideUrl').val();
	$.ajax({
	    url: hideUrl,
	    type: 'POST',
	    data:{'id':id,'status':status,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				document.location.reload();
			}else if(res.code==400){
				alert('可返现金额不足，操作失败！');
			}else{
				alert('获取记录失败，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function doDelViewHistory(all){
	var url	= $('#hdUrl').val();
	var start = '';
	var end = '';
	if(all==0){
		start	= $('#txtStart').val();
		end		= $('#txtEnd').val();
	}
	$.ajax({
	    url: url,
	    type: 'GET',
	    data:{'start':start,'end':end,'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				alert("清空浏览数据成功！");
			}else{
				alert('操作失败，请重新尝试！');
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function ajaxGet(url,reload){
	$.ajax({
	    url: url,
	    type: 'GET',
	    data:{'rnum':Math.random()},
	    dataType: 'json',
	    success: function(res){
			if(res.code==200){
				if(reload){
					document.location.reload();
				}else{
					alert('操作成功');
				}
			}else{
				if(res.message!=''){
					alert(res.message);
				}else{
					alert('操作失败，请重新尝试！');
				}
			}
		},
		error:function(res){
			alert(res.responseText);
		}
	});
}

function showMenu(type){
	var obj	= $('#menu-'+type+"-detail");
	obj.toggle();
}